//
//  ViewController.m
//  02.18Attention2(纯代码)
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(void)addButtonWithTitle:(NSString *)title andFrame:(CGRect)frame andTag:(int)tag andColor:(UIColor *)color
{
    UIButton *btn=[[UIButton alloc]initWithFrame:frame];
    
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:color forState:UIControlStateNormal];
    btn.titleLabel.font=[UIFont systemFontOfSize:20]; //按钮上字体大小
    btn.tag=tag;
    [btn addTarget:self action:@selector(btnPressed:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:btn];
}

-(void)btnPressed:(UIButton *)sender
{
    switch (sender.tag) {
        case 1:{
            UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"弹出框信息" message:@"信息~~~~~" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
            [alertView show];
        }
            break;
        case 2:{
            UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"错误" message:@"确定关闭吗？" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles: @"不关闭",@"待定",nil];
            [alertView show];
        }
            break;
        case 3:{
            UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"登录" message:@"请输入用户名和密码" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: @"取消",nil];
            alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
            [alertView show];
        }
            break;
        case 4:{
            UIActionSheet *sheet =[[UIActionSheet alloc]initWithTitle:@"小明,一起去吃饭吗？" delegate:self cancelButtonTitle:@"我吃过了，你去吧" destructiveButtonTitle:@"一起去吃" otherButtonTitles:@"一起吃KFC",@"一起吃MC" ,nil];
            [sheet showInView:self.view];
        }
            break;
        default:
            break;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.label=[[UILabel alloc]init];
    self.label.frame=CGRectMake(25, 425, 100, 50);
    self.label.text = @"label";
    self.label.textColor=[UIColor blackColor];
    [self.view addSubview:self.label];
    [self addButtonWithTitle:@"简单提示框" andFrame: CGRectMake(25,25,100,50) andTag:1 andColor:[ UIColor blueColor]];
    [self addButtonWithTitle:@"多按钮" andFrame: CGRectMake(25,125,100,50) andTag:2 andColor:[ UIColor blueColor]];
    [self addButtonWithTitle:@"带输入框" andFrame: CGRectMake(25,225,100,50) andTag:3 andColor:[ UIColor blueColor]];
    [self addButtonWithTitle:@"操作表" andFrame: CGRectMake(25,325,100,50) andTag:4 andColor:[ UIColor blueColor]];
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if ([alertView.title isEqualToString:@"登录"]) {
        NSString *info = [NSString stringWithFormat:@"用户名:%@ 密码:%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text];
        self.label.text = info;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
